package com.fuh.study.factory.work;

/**
 * @创建人 fuh
 * @创建时间 2021/4/12  17:02
 * @描述
 */
public class CarFactory {
    // 使用java反射+静态工厂模式
    public static Car getCarByClassName(String className) {
        try {
            Class<?> aClass = Class.forName(className);
            Object car = aClass.newInstance();
            if (car instanceof Car) {
                return (Car) car;
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
